package com.job.sun.HomeWork0715;

import java.util.Arrays;

/**
 * @author 张春阳
 * @version 1.0
 * @since 2022-07-16 13:35:09
 */
public class String02 {
    public static void main(String[] args) {
        //1.字符串对象的构造方法
        //(1).byte[]
        byte[] bytes =new byte[]{99,100,101,102,103,104,105,106};
        String s1 =new String(bytes);
        //                              位置    长度
        String s2 =new String(bytes, 1, 3);
        System.out.println(s1);
        System.out.println(s2);
         //(2). char[]
         char[] chars =new char[]{'张','A','=','!',66,99};
        System.out.println(new String(chars));
        //                              初始位置   个数
        String s4  = new String(chars, 1, 3);
        System.out.println(s4);

        //2.字符串--->字节数组
        String s5 ="夏日一天一个雪糕";
        //一个汉字用三个字节表示 byte类型范围较小
        byte[] bytes1 = s5.getBytes();
        System.out.println(Arrays.toString(bytes1));
        //3.字符串---->字符数组

        char[] chars1 = s5.toCharArray();
        System.out.println(Arrays.toString(chars1));
        //4.指定下标出字符
        char c = s5.charAt(3);
        System.out.println(c);
        //5.计算字符串长度
        System.out.println(s5.length());
        for (int i=0;i<s5.length();i++){
            System.out.println(i+"="+s5.charAt(i));
        }
        //6.求字符串内大写字母的个数
        //(1).利用循环 和编码集 找出字符串的大写字母个数
        //(2.)循环 char 内方法
        String s6 ="package com.job.sun.HomeWork0715";
        int count = 0;
        for (int i=0;i<s6.length();i++){
            if (Character.isUpperCase(s6.charAt(i))){
                count++;
            }
        }
        System.out.println(count);

    }
}